# -*- coding: utf-8 -*-

from selenium import webdriver
import unittest, time

class Method(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.base_url = "http://blog.csdn.net"
        self.verificationErrors = []
    
    def test_CSDN(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        
        print driver.page_source     #返回当前网页的源码  
        print driver.title           #返回当前浏览器的title
        print driver.current_url     #获得当前页面的url
        print driver.window_handles  #返回当前浏览器窗口的句柄
        driver.maximize_window()
        
        driver.find_element_by_xpath("//a[contains(text(),'登录')]").click()
        driver.switch_to_frame("logfrm")  
        driver.find_element_by_id("u").clear()
        driver.find_element_by_id("u").send_keys("testMiaozhen")
        driver.find_element_by_id("p").clear()
        driver.find_element_by_id("p").send_keys("miaozhen")
        
        driver.find_element_by_xpath("//a[@id='aLogin']/span").click()   
  
        time.sleep(10)        
        driver.quit()

if __name__ == "__main__":
    unittest.main()
        
